package org.jeecg.modules.rental.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
//import org.equ.common.model.dto.RentalManageCarReq;
//import org.equ.common.model.req.EBikeTrackReq;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.rental.req.EBikeTrackReq;
import org.jeecg.modules.rental.req.RentalManageCarReq;
import org.jeecg.modules.rental.service.*;
import org.springframework.web.bind.annotation.*;

@Api(tags="客户端设备信息")
@RestController
@RequestMapping("/ctrl/e-bike")
@Slf4j
@RequiredArgsConstructor
public class EBikeController {

    private final IEquService equService;
    private final IRentalEBikeService rentalCarService;
    private final IRentalAccountPackageService accountPackageService;
    private final IRentalAccountService rentalPayAccountService;
    private final ICtrlEBikeService ctrlEBikeService;

    @PostMapping("/on")
    @ApiOperation("上电")
    public Result powerOn(){
        return Result.OK("equ.poweron.success", equService.powerOn());
    }

    @PostMapping("/off")
    @ApiOperation("断电")
    public Result powerOff(){
        return Result.OK("equ.poweroff.success", equService.powerOff());
    }

    @PostMapping("/locked")
    @ApiOperation("设防")
    public Result locked(){
        return Result.OK("equ.defense.success", equService.locked());
    }

    @PostMapping("/unlock")
    @ApiOperation("撤防")
    public Result unlock(){
        return Result.OK("equ.disarming.success", equService.unlock());
    }

    @PostMapping("/search")
    @ApiOperation("寻车")
    public Result search(){
        return Result.OK("寻车成功", equService.search());
    }

    @PostMapping("/unlock-seat")
    @ApiOperation("座位锁")
    public Result unlockSeat(){
        return Result.OK("打开座位锁", equService.unlockSeat());
    }

    @PostMapping("/enableSportMode")
    @ApiOperation("开启运动模式")
    public Result enableSportMode(@RequestBody RentalManageCarReq rentalManageCar) {
        try {
            // 调用 IControlAPI 中的开启运动模式方法
            boolean isSuccess = equService.enableSportMode(rentalManageCar.getEnable());

            if (isSuccess) {
                return Result.OK("运动模式开启成功");
            } else {
                return Result.error("运动模式开启失败");
            }
        } catch (Exception e) {
            log.error("开启运动模式失败", e);
            return Result.error("开启运动模式失败：" + e.getMessage());
        }
    }
    @GetMapping(value = "/track-list")
    @ApiOperation(value="车辆轨迹")
    public Result<String> carTrackList(EBikeTrackReq trackReq) throws JsonProcessingException {
        String carTrackList = ctrlEBikeService.trackListByAccount(trackReq);
        return Result.OK(carTrackList);
    }

    @GetMapping(value = "/get-info")
    @ApiOperation(value="获取车辆定位 电量相关信息")
    public Result<String> getInfo(String carCode) throws JsonProcessingException {
       Boolean ist=rentalCarService.pushEBikeInfo(carCode);
       if (ist){
           return Result.OK();
       }else {
           return Result.error("获取失败");
       }
    }

}
